#include "Text.h"

Text::Text(string fontFile, string text, float x, float y, int style, int red, int green, int blue, int psize)
{
    this->fontFile = fontFile;
    this->text = text;
    this->style = style;
    this->x = x;
    this->y = y;
    collor.r = red;
    collor.g = green;
    collor.b = blue;


    font = TTF_OpenFont(fontFile.c_str(), psize);
    textSurface = TTF_RenderText_Blended(font, text.c_str(), collor);

    TTF_SetFontStyle(font, style);

    rect.x = x;
	rect.y = y;
	rect.w = textSurface->w;
	rect.h = textSurface->h;

}

Text::~Text()
{
    SDL_FreeSurface(textSurface);
	TTF_CloseFont(font);
}

void Text::Render(SDL_Surface* screen)
{
    rect.x = x;
    rect.y = y;

    SDL_BlitSurface(textSurface, NULL, screen, &rect);
}

void Text::changeText(string text)
{
    SDL_FreeSurface(textSurface);
    this->text = text;
    textSurface = TTF_RenderText_Blended(font, text.c_str(), collor);

    rect.x = x;
	rect.y = y;
	rect.w = textSurface->w;
	rect.h = textSurface->h;
}

void Text::changeStyle(int style)
{
    SDL_FreeSurface(textSurface);
    TTF_SetFontStyle(font, style);
    textSurface = TTF_RenderText_Blended(font, text.c_str(), collor);

    rect.x = x;
	rect.y = y;
	rect.w = textSurface->w;
	rect.h = textSurface->h;
}

void Text::changeColor(int red, int green, int blue)
{
    SDL_FreeSurface(textSurface);
    collor.r = red;
    collor.g = green;
    collor.b = blue;
    textSurface = TTF_RenderText_Blended(font, text.c_str(), collor);

    rect.x = x;
	rect.y = y;
	rect.w = textSurface->w;
	rect.h = textSurface->h;
}

void Text::changeSize(int size)
{
    SDL_FreeSurface(textSurface);
    font = TTF_OpenFont(fontFile.c_str(), size);
    textSurface = TTF_RenderText_Blended(font, text.c_str(), collor);

    rect.x = x;
	rect.y = y;
	rect.w = textSurface->w;
	rect.h = textSurface->h;
}

